import Mock from "mockjs";

let baseUrl = 'http://www.mock.com/test';

// 设置1秒后再响应
Mock.setup({ timeout: 1000 });

// 设置1秒至4秒间响应
// Mock.setup({ timeout: '1000-4000' });

//定义url 请求方式 返回数据
// Mock.mock(baseUrl + "/home/product/list?id=0","get",function() {
//   return Mock.mock({
//     code: 0,
//     data: {
//       imgUrl: "1s1s1s1s1d",
//       title: "商品标题传入数据12121212121",
//       'originalPrice|500-300':200,
//       'salesVolume|800-1500':1000,
//       'couponPrice|200-300':400,
//     },
//     message: "操作成功"
//   });
// });
let num = 4;
let index = 0;

Mock.mock(RegExp(baseUrl + "/home/product/list" + ".*"), "get", function () {

    let row = {
        imgUrl: "1s1s1s1s1d",
        title: "商品标题传入数据aaaaaaaaaaaa",
        'originalPrice|500-300': 200,
        'salesVolume|800-1500': 1000,
        'couponPrice|200-300': 400,
    };
    index++;
    if (index > 4) {
        num = 1;
    }
    let rows = [];
    for (let index = 0; index < num; index++) {
        rows.push(row);
    }

    return Mock.mock({
        S: 1,
        rows: rows,
        msg: ""
    });
});


Mock.mock(baseUrl + "/product/detail?id=0", "get", function () {
    return Mock.mock({
        S: 1,
        msg: "",
        data: {
            imgUrl: "//img.alicdn.com/imgextra/i4/2972194561/TB2QeuVCuuSBuNjSsziXXbq8pXa_!!2972194561-0-item_pic.jpg_430x430q90.jpg",
            title: "商品商品商品商品商品商品商品商品商品商品商品商品商品商品商品商品商品商品商品商品商品商品商品商品商品商品",
            "originalPrice|300-2000": 300,
            "salesVolume|1000-100000": 10000,
            "couponPrice|100-300": 200,
            imgDetailUrls: [
                //图片地址的集合
                "//img.alicdn.com/imgextra/i4/2972194561/TB2QeuVCuuSBuNjSsziXXbq8pXa_!!2972194561-0-item_pic.jpg_430x430q90.jpg",
                "//img.alicdn.com/imgextra/i4/2972194561/TB2QeuVCuuSBuNjSsziXXbq8pXa_!!2972194561-0-item_pic.jpg_430x430q90.jpg",
                "//img.alicdn.com/imgextra/i3/2972194561/TB2WhAiuHsrBKNjSZFpXXcXhFXa_!!2972194561.jpg_430x430q90.jpg",
                "//img.alicdn.com/imgextra/i3/2972194561/TB2WhAiuHsrBKNjSZFpXXcXhFXa_!!2972194561.jpg_430x430q90.jpg"
            ],
            recommends: [
                {
                    imgUrl: "//img.alicdn.com/imgextra/i4/2972194561/TB2QeuVCuuSBuNjSsziXXbq8pXa_!!2972194561-0-item_pic.jpg_430x430q90.jpg",
                    title: "1推荐传入商品标题传入商品标题传入商品标题",
                    "originalPrice|300-2000": 300,
                    "salesVolume|100-100000": 10000,
                    "couponPrice|100-300": 200
                },
                {
                    imgUrl: "//img.alicdn.com/imgextra/i4/2972194561/TB2QeuVCuuSBuNjSsziXXbq8pXa_!!2972194561-0-item_pic.jpg_430x430q90.jpg",
                    title: "2推荐传入商品标题传入商品标题传入商品标题",
                    "originalPrice|300-2000": 300,
                    "salesVolume|100-100000": 10000,
                    "couponPrice|100-300": 200
                }
            ]
        }
    });
});
